package com.example.mybatis_;



import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

public class AutoMapper {
    public static void main(String[] args) {

        GlobalConfig config = new GlobalConfig();
        AutoGenerator  ag = new AutoGenerator();
        String path = System.clearProperty("user.dir"); //
        config.setOutputDir(System.getProperty("user.dir") + "/src/main/java");// 输出路径
        config.setMapperName("%sMapper");
        config.setServiceName("%sService");
        config.setServiceImplName("%sServiceImpl");
        config.setControllerName("%sController");
        config.setIdType(IdType.AUTO); // 设置ID
        ag.setGlobalConfig(config);

        //设置数据源
        DataSourceConfig sourceConfig = new DataSourceConfig();
        sourceConfig.setDriverName("com.mysql.jdbc.driver");
        sourceConfig.setUrl("jdbc:mysql://localhost:3306/test");
        sourceConfig.setUsername("root");
        sourceConfig.setPassword("123456");
        ag.setDataSource(sourceConfig);

        // 设置Packet信息
        PackageConfig packageConfig = new PackageConfig();

        packageConfig.setModuleName("order"); //设置模块名称，相当于包名，包含service controller

        packageConfig.setParent("com.example");

        ag.setPackageInfo(packageConfig);


        //设置策略
        StrategyConfig strategyConfig = new StrategyConfig();
        strategyConfig.setNaming(NamingStrategy.underline_to_camel);
        strategyConfig.setColumnNaming(NamingStrategy.underline_to_camel);// 支持驼峰
        ag.setStrategy(strategyConfig);

        //代码生成
        ag.execute();


    }
}
